#include "CCoroutineTimerContext.h"

namespace TB
{
	CCoroutineTimerContext::CCoroutineTimerContext(volatile UINT64* pqwCurTime):
		m_oTimerMgr(true, pqwCurTime)
	{
	}

	ITimerContext::DStopTimer CCoroutineTimerContext::StartTimer(UINT64 qwMilliSeconds, const std::function<void()>& cbOnTimer)
	{
		CTimerMgr& roTimerMgr = m_oTimerMgr;
		auto sTimerUID = roTimerMgr.StartTimer(qwMilliSeconds, 1, [cbOnTimer](const STimerUID&, UINT32, UINT32)
		{
			cbOnTimer();
		});
		return [&roTimerMgr, sTimerUID]() { roTimerMgr.StopTimer(sTimerUID); };
	}
}